import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller.dart';

/// 初始化进度指示器组件
/// 
/// 特性：
/// - 实时显示初始化进度
/// - 美观的进度条设计
/// - 百分比文字显示
class SplashProgressIndicator extends GetView<SplashController> {
  /// 进度条宽度
  final double width;
  
  /// 进度条高度
  final double height;
  
  /// 进度条背景色
  final Color? backgroundColor;
  
  /// 进度条颜色
  final Color? progressColor;
  
  /// 文字颜色
  final Color? textColor;
  
  /// 是否显示百分比文字
  final bool showPercentage;

  const SplashProgressIndicator({
    super.key,
    this.width = 200,
    this.height = 4,
    this.backgroundColor,
    this.progressColor,
    this.textColor,
    this.showPercentage = true,
  });

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      final progress = controller.getInitializationProgress();
      return Column(
        children: [
          Container(
            width: width,
            height: height,
            decoration: BoxDecoration(
              color: backgroundColor ?? Colors.white.withValues(alpha: 0.3),
              borderRadius: BorderRadius.circular(height / 2),
            ),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(height / 2),
              child: LinearProgressIndicator(
                value: progress,
                backgroundColor: Colors.transparent,
                valueColor: AlwaysStoppedAnimation<Color>(
                  progressColor ?? Colors.white,
                ),
              ),
            ),
          ),
          if (showPercentage) ...[
            const SizedBox(height: 8),
            Text(
              '${(progress * 100).toInt()}% 完成',
              style: TextStyle(
                fontSize: 12,
                color: textColor ?? Colors.white60,
              ),
            ),
          ],
        ],
      );
    });
  }
}
